package com.itheima.web;

import com.itheima.pojo.Category;
import com.itheima.result.R;
import com.itheima.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Author: 斌
 * @DateTime: 2023年02月06日  20:00:06
 * @Description: com.itheima.web
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/page")
    public R selectCategory(Integer page, Integer pageSize,Category category){
      return categoryService.selectCategory(page,pageSize,category);
    }
    @PostMapping
    public R addCategory(@RequestBody Category category, HttpSession session){
        return categoryService.addCategory(category,session);
    }
    @PutMapping
    public R updateCategory(@RequestBody Category category, HttpSession session){

        return categoryService.updateCategory(category,session);
    }
    @DeleteMapping()
    public R deleteCategory( Long id){
        return categoryService.deleteCategory(id);
    }

    @GetMapping("/list")
    public R listCategory(Category category){
        return categoryService.listCategory(category);
    }
}
